export const hasPermission = {
  install(Vue) {
    Vue.directive('hasPermission', {
      bind(el, binding, node) {
        var flag = false;//默认不显示
        let UserInfo = node.context.$store.getters.getUserInfo;
        let permissions = node.context.$store.getters.getUserPermission;
        let roles =  node.context.$store.getters.getUserRoles
        //获取使用组件的value中
        var value = binding.value;
        //若是超级管理员
        let rolesLenth = roles.length;
        for (let index = 0; index < rolesLenth; index++) {
          if (roles[index].roleName === 'super_admin') {
            flag = true;
            break;
          }
        }
        let permissionLenth = permissions.length;
        for (let index = 0; index < permissionLenth; index++) {
          if (permissions[index].perms == value) {
            //若有该权限的按钮则显示
            flag = true;
          }

        }
        if (!flag) {
          el.setAttribute("disabled", true);
          el.classList.add("is-disabled",'none');
          el.style.display = 'none'
        }
      }
    })
  }
}
